//
//  CustomTabBar.m
//  TabBarTest
//
//  Created by xc on 2016/11/2.
//  Copyright © 2016年 xc. All rights reserved.
//

#import "CustomTabBar.h"
#import "UIView+Extension.h"

@interface CustomTabBar ()


@end
@implementation CustomTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *centerImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_bg"] highlightedImage:[UIImage imageNamed:@"home_bg"]];
        centerImage.highlighted = YES;
        centerImage.bounds = CGRectMake(0, 0, 55, 55);
//        centerImage.backgroundColor = [UIColor lightGrayColor];
        centerImage.layer.cornerRadius = 27.5;
        centerImage.clipsToBounds = YES;
        [self addSubview:centerImage];
        self.centerImage = centerImage;
    }
    return self;
}

/**
 *  加号按钮点击
 */


/**
 *  想要重新排布系统控件subview的布局，推荐重写layoutSubviews，在调用父类布局后重新排布。
 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 1.设置加号按钮的位置
    self.centerImage.centerX = self.width*0.5;
    self.centerImage.centerY = self.height*0.5-5;
    
    // 2.设置其他tabbarButton的frame
//    CGFloat tabBarButtonW = self.width / 5;
    CGFloat tabBarButtonIndex = 0;
    NSLog(@"%ld",self.subviews.count);
    for (UIView *child in self.subviews) {
        Class class = NSClassFromString(@"UITabBarButton");
        if ([child isKindOfClass:class]) {
            // 设置x
//            child.x = tabBarButtonIndex * tabBarButtonW;
//            // 设置宽度
//            child.width = tabBarButtonW;
            // 增加索引
            tabBarButtonIndex++;
            if (tabBarButtonIndex == 3) {
                child.centerY = self.height*0.5-8;
            }
        }
    }
}

@end
